<?php


/**
 * 新闻通告
 * Enter description here ...
 * @author Admin
 *
 */
class NewsAction extends CommonAction{

	
	/**
	 * 新闻通告详情
	 * Enter description here ...
	 */
    public function index()    {
		$id = GetNum($_GET['id']);  //主键ID
		
    	$article = D('Article');   //文章
		$article_categories = M('Article_categories');  //文章分类
		$notice_map=array(
    		'state'=>array('eq',1),
    		'cid'=>array('eq',1)  //公告资讯 1
    	);
    	$notice = $article->getdata($notice_map,5);     //获取公告资讯下属发布文章
    	
    	
    	$testimonials_map=array(
    		'state'=>array('eq',1),
    		'cid'=>array('eq',2)  //常见问题 2
    	);
    	$testimonials = $article->getdata($testimonials_map,5);  //常见问题下属发布文章
    	
		
    	
		$data = $article->find($id);   //当前文章
		$categories = $article_categories->find($data['cid']);  //当前文章分类
	
		if ($data['state'] != 1)   //不是发布状态
			$data = null;
		
		$previousmap = array(
			'id' =>array('lt',$data['id']),
			'cid'=>array('eq',$data['cid']),
		);
		$previous = $article->where($previousmap)->order('id desc')->find();  //上一条文章
		
		$nextmap = array(
			'id' =>array('gt',$data['id']),
			'cid'=>array('eq',$data['cid']),
		);
		$next = $article->where($nextmap)->find();  //下一条文章
		
		
		$recentmap = array(
			'id'=>array('neq',$data['id']),
			'cid'=>array('eq',$data['cid']),
		);
		$recent = $article->where($recentmap)->order('id desc')->limit(9)->findAll();  //最近发布的文章
		
		
		$this->assign('data',$data);
		$this->assign('notice',$notice);
    	$this->assign('testimonials',$testimonials);
		$this->assign('categories',$categories);
		$this->assign('previous',$previous);
		$this->assign('next',$next);
		$this->assign('recent',$recent);
		
        $this->display();
    }

    
    
    
    /**
     * 相关新闻列表 
     * 新闻通告、常见问题明细导航栏连接
     * Enter description here ...
     */
	public function newslist(){
		$id = GetNum($_GET['id']);    //文章分类ID
		
		$article_categories = M('Article_categories');
		$categories = $article_categories->find($id);  //文章分类
		
		$article = D('Article');
		
		
		//....获取分类下属最新文章
		$datamap=array(
    		'state'=>array('eq',1),
    		'cid'=>array('eq',$id)  
    	);
		
		$count = $article->where($datamap)->count();
		$limit = $this->page($count,1);
		$data = $article->getdata($datamap,$limit);
		
		
		
		
		//...获取新闻通告和常见问题 [左侧列表显示 info.html]
		$notice_map=array(
    		'state'=>array('eq',1),
    		'cid'=>array('eq',1)  //新闻通告1
    	);
    	$notice = $article->getdata($notice_map,5);
    	
    	$testimonials_map=array(
    		'state'=>array('eq',1),
    		'cid'=>array('eq',2)  //常见问题2
    	);
    	
    	$testimonials = $article->getdata($testimonials_map,5);
    	
    	
		$this->assign('categories',$categories);
		$this->assign('notice',$notice);
    	$this->assign('testimonials',$testimonials);
		$this->assign('data',$data);
		
		
		$this->display();
	}
	
	
	
}
?>